

class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        
        vector<vector<int>> ret;
        if(root==nullptr)return ret;
        queue<TreeNode*>q;
        q.push(root);

        while(q.size())
        {
            int sz=q.size();
            vector<int> vtmp;
            while(sz--)
            {
                TreeNode*tmp=q.front();
                q.pop();
                if(tmp->left) q.push(tmp->left);
                if(tmp->right) q.push(tmp->right);
                vtmp.push_back(tmp->val);
            }
            ret.push_back(vtmp);
        }
        return ret;

        

    }
};